package com.jemmyee.pizza.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.management.j2ee.statistics.Statistic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import sun.jdbc.odbc.ee.DataSource;

import com.jemmyee.core.dao.BaseDaoImpl;
import com.jemmyee.pizza.statistic.ApplyStatistic;
import com.jemmyee.pizza.statistic.DailyStatistic;
import com.jemmyee.pizza.statistic.DredgeStatistic;
import com.jemmyee.pizza.statistic.ExecrptStatistic;
import com.jemmyee.pizza.statistic.PreExcerptStatistic;

/**
 * @author qiuchao 2011-3-5
 */
@Repository("statisticDao")
public class StatisticDaoImpl /* extends BaseDaoImpl<Statistic> extends
		JdbcDaoSupport */implements IStatisticDao {
	private JdbcTemplate jdbcTemplate;

	

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	@SuppressWarnings("unchecked")
	public List<ApplyStatistic> applyStatistic(String sql) {
		System.out.println(sql);
		return (List<ApplyStatistic>) jdbcTemplate.query(sql,new ApplyStatisticMapper());
			
	}
	@SuppressWarnings("unchecked")
	public List<PreExcerptStatistic> preExcerptStatistic(String sql) {
		System.out.println(sql);
		return (List<PreExcerptStatistic>) jdbcTemplate.query(sql,new PreExcerptStatisticMapper());
	}

	@SuppressWarnings("unchecked")
	public List<DredgeStatistic> dredgeStatistic(String sql) {
		System.out.println(sql);
		return (List<DredgeStatistic>) jdbcTemplate.query(sql,new DredgeStatisticMapper());
	}
	
	@SuppressWarnings("unchecked")
	public List<ExecrptStatistic> excerptStatistic(String sql) {
		System.out.println(sql);
		return (List<ExecrptStatistic>) jdbcTemplate.query(sql,new ExecrptStatisticMapper());
	}

	@SuppressWarnings("unchecked")
	public List<DailyStatistic> dailyStatistic(String sql) {
		System.out.println(sql);
		return (List<DailyStatistic>) jdbcTemplate.query(sql,new DailyStatisticMapper());
	}
	
	protected class ApplyStatisticMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			ApplyStatistic as = new ApplyStatistic();
			as.setQuantity(rs.getInt("quantity"));
			as.setTotalPrice(rs.getFloat("total_price"));
			as.setUnitPrice(rs.getFloat("unit_price"));
			return as;
		}
	}
	
	protected class PreExcerptStatisticMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			PreExcerptStatistic pes = new PreExcerptStatistic();
			pes.setDetailName(rs.getString("detail_name"));
			pes.setQuantity(rs.getInt("quantity"));
			pes.setTotalGasQuantity(rs.getFloat("total_gas_quantity"));
			pes.setTotalPrice(rs.getFloat("total_price"));
			return pes;
		}
	}
	
	protected class DredgeStatisticMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			DredgeStatistic ds = new DredgeStatistic();
			ds.setDetailName(rs.getString("detail_name"));
			ds.setQuantity(rs.getInt("quantity"));
			ds.setUnitPrice(rs.getFloat("unit_price"));
			ds.setTotalPrice(rs.getFloat("total_price"));
			ds.setAboutDoor(rs.getString("about_door"));
			return ds;
		}
	}

	protected class ExecrptStatisticMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			ExecrptStatistic es = new ExecrptStatistic();
			es.setMingxi(rs.getString("mingxi"));
			es.setYi(rs.getFloat("yi"));
			es.setEr(rs.getFloat("er"));
			es.setSan(rs.getFloat("san"));
			es.setSi(rs.getFloat("si"));
			es.setWu(rs.getFloat("wu"));
			es.setLiu(rs.getFloat("liu"));
			es.setQi(rs.getFloat("qi"));
			es.setBa(rs.getFloat("ba"));
			es.setJiu(rs.getFloat("jiu"));
			es.setShi(rs.getFloat("shi"));
			es.setShiyi(rs.getFloat("shiyi"));
			es.setShier(rs.getFloat("shier"));
			return es;
		}
	}

	protected class DailyStatisticMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			DailyStatistic ds = new DailyStatistic();
			ds.setDailyDate(rs.getDate("n_date"));
			ds.setTingyuhuwai(rs.getFloat("tingyuhuwai"));
			ds.setTingyuhunei(rs.getFloat("tingyuhunei"));
			ds.setLanyanhuwai(rs.getFloat("lanyanhuwai"));
			ds.setLanyanhunei(rs.getFloat("lanyanhunei"));
			ds.setShanchenghuwai(rs.getFloat("shanchenghuwai"));
			ds.setShanchenghunei(rs.getFloat("shanchenghunei"));
			ds.setTianxinhuwai(rs.getFloat("tianxinhuwai"));
			ds.setTianxinhunei(rs.getFloat("tianxinhunei"));
			ds.setTingyuhuwai_1(rs.getInt("tingyuhuwai_1"));
			ds.setTingyuhunei_1(rs.getInt("tingyuhunei_1"));
			ds.setLanyanhuwai_1(rs.getInt("lanyanhuwai_1"));
			ds.setLanyanhunei_1(rs.getInt("lanyanhunei_1"));
			ds.setShanchenghuwai_1(rs.getInt("shanchenghuwai_1"));
			ds.setShanchenghunei_1(rs.getInt("shanchenghunei_1"));
			ds.setTianxinhuwai_1(rs.getInt("tianxinhuwai_1"));
			ds.setTianxinhunei_1(rs.getInt("tianxinhunei_1"));
			ds.setQuantity(rs.getInt("quantity"));
			ds.setShisan(rs.getFloat("shisan"));
			ds.setErshi(rs.getFloat("ershi"));
			ds.setErshisan(rs.getFloat("ershisan"));
			return ds;
		}
	}

	

	
}
